package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import dao.StudentSql;
import dao.TeacherSql;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class AlterStudentServlet
 */
public class AlterInfoServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public AlterInfoServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.setCharacterEncoding("utf-8");
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        String ID = request.getParameter("ID");
        String Sex = request.getParameter("Sex");
        String Phone = request.getParameter("Phone");
        String Email = request.getParameter("Email");
        String Type = request.getParameter("Type");
        if(Type.equals("student")){
            boolean a = StudentSql.updateCustomer(ID, Email,Sex,Phone);
            if (a){
                response.setHeader("refresh", "1;URL=Student_Info.jsp");
            }else {
                out.println("修改信息失败");
                response.setHeader("refresh", "1;URL=Student_Info.jsp");
            }

        }else{
            boolean a = TeacherSql.updateCustomer(ID, Email,Sex,Phone);
            if (a){
                response.setHeader("refresh", "1;URL=Teacher_Info.jsp");
            }else {
                out.println("修改信息失败");
                response.setHeader("refresh", "1;URL=Teacher_Info.jsp");
            }

        }
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }
}
